#pragma once
#include "AstroPanic.h"
#include "utils\Log.h"
#include "src\gamestates\RunState.h"
#include "base\Framework.h"
#include "dxstdafx.h"
#include "base\Engine.h"
#include "game\World.h"
#include "src\effects\Background.h"
#include "src\gamestates\StartState.h"
#include "SimpleHighscoreService.h"
#include "src\gamestates\DummyState.h"
#include "particles\ParticleSystem.h"

void AstroPanic::initialize() {		
	gEngine->getResourceManager().loadFont("XScale","content\\fonts\\X-SCALE_.TTF","xscale",30,false);
	gEngine->getResourceManager().loadFont("BigXScale","content\\fonts\\X-SCALE_.TTF","xscale",48,false);	
	Background* background = new Background();
	gEngine->getWorld().attachNode(background,"Buffer");
	gEngine->addGameState(new StartState());	
	gEngine->addGameState(new RunState("Run"));		
	gEngine->activateGameState("Start");		
	//gEngine->addGameState(new DummyState("Dummy"));			
	//gEngine->activateGameState("Dummy");	
}

void AstroPanic::loadContent(ds::ResManager& resourceManager) {	
	ds::ParticleManager* pm = static_cast<ds::ParticleManager*>(gEngine->getWorld().getNode("Particles"));
	assert(pm != 0);
	ds::ParticleSystem* ps = pm->prepare("Starfield");
	ps->addAffector(new RespawnAffector());
	pm->start(ds::Vec3(10,10,0),ps);
}

//-----------------------------------------------------------------------------
// Name: wWinMain()
// Desc: The application's entry point
//-----------------------------------------------------------------------------
INT WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE, LPWSTR, INT ) {	
	FILE* pFile = fopen("application.log", "w");
	FileOutputHandler::Stream() = pFile;

	LOG(logINFO) << "Starting game";	
	ds::Settings settings;
	settings.width = 1024;
	settings.height = 768;
	settings.title = "AstroPanic";
	settings.mode = 1;
	settings.synched = true;
	settings.fullscreen = false;
	settings.postProcessing = false;
	//settings.clearColor = ds::Color(0.4f,0.1f,0.8f,1.0f);
	ShowCursor(false);
	AstroPanic *tt = new AstroPanic();
	ds::CFramework *framework = new ds::CFramework(tt);
	framework->initialize(hInstance,settings);
	LOG(logINFO) << "Running game now";
	framework->Run();
	LOG(logINFO) << "Game ended";
	framework->Release();
	delete framework;
	return 0; 
}
